//
//  SelectVideoDeviceModel.m
//  Rail
//
//  Created by hychen on 2018/3/25.
//  Copyright © 2018年 Hychen. All rights reserved.
//

#import "SelectVideoDeviceModel.h"

@implementation VideoIpTypeModel
MJCodingImplementation
- (void)setType:(VideoDeviceIPAddressType)type {
    _type = type;
}
@end

@implementation SelectVideoDeviceModel
MJCodingImplementation
+ (NSDictionary *)mj_replacedKeyFromPropertyName {
    return @{@"operatorUser":@"operator"};
}

- (instancetype)init {
    if (self = [super init]) {
        _userId = -1;
    }
    return self;
}

- (void)setupTypeModel {
    if ([_in_ipaddress isKindOfClass:[NSString class]] && _in_ipaddress.length > 0) {
        VideoIpTypeModel *typeModel = [VideoIpTypeModel new];
        typeModel.isSelect = NO;
        typeModel.user = _auth_user;
        typeModel.pwd = _auth_pwd;
        typeModel.ip = _in_ipaddress;
        typeModel.port = _port;
        typeModel.showName = @"内网地址";
        _inTypeModel = typeModel;
        typeModel.type = VideoDeviceIPAddressTypeIn;
        _type = VideoDeviceIPAddressTypeIn;
    }
    if ([_out_ipaddress isKindOfClass:[NSString class]] && _out_ipaddress.length > 0) {
        VideoIpTypeModel *typeModel = [VideoIpTypeModel new];
        typeModel.isSelect = YES;
        typeModel.user = _auth_user;
        typeModel.pwd = _auth_pwd;
        typeModel.ip = _out_ipaddress;
        typeModel.port = _map_port;
        typeModel.showName = @"外网地址";
        _outTypeModel = typeModel;
        typeModel.type = VideoDeviceIPAddressTypeOut;
        _type = VideoDeviceIPAddressTypeOut;
    }
}

- (int)startChan {
    if (_startChan > 0) {
        return _startChan;
    }
    return [self.chid intValue];
}

- (int)chanNum {
    if (_chanNum > 0) {
        return _chanNum;
    }
    return [self.ch_count intValue];
}

- (instancetype)initWithHomeVideoModel:(HomeVideoHistoryModel *)model {
    SelectVideoDeviceModel *deviceModel = [SelectVideoDeviceModel new];
    deviceModel.device_name = model.device_name;
    deviceModel.area_name = model.area_name;
    deviceModel.areaid = model.areaid;
    deviceModel.deviceid = model.deviceid;
    deviceModel.snapshot_url = model.snapshot_url;
    return deviceModel;
}
@end
